<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}"/>
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/Managerstyle.css}"/>
<script th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
</head>
<body>
	
	<div class="contain">
		<div class="query">
			<h3>排课</h3>
			<h4>查找开课计划</h4>
			<select id="selectAcdm">
				<option>请选择学院</option>
				<option th:each="acadamy:${acadamylist}" th:value="${acadamy.acdmid}"  th:text="${acadamy.acdmname}" style="width: 220px;"></option>
			</select>
			<select id="selectMj" name="mjid" style="width: 150px;">
				<option>请选择专业</option>
			</select>
			<select id="selectTerm" name="termId" >
				<option>请选择学期</option>
				<option th:each="term:${termlist}" th:value="${term.termId}" th:text="${term.termName}"></option>
			</select>
			<input type="button" value="查 询" class="btn btn-info" id="getCoursePlan">
			<br>
			<table class="table table-hover">
					<tr >
						<td width="150">开课计划号</td>
						<td width="216">专业</td>
						<td>班级</td>
						<td>教师名称</td>
						<td>课程名称</td>
						<td>所需教室类型</td>
						<td width="177">操作</td>
					</tr>
				<tbody id="cp">
					<tr>
						<td></td>
					</tr>
				</tbody>
			</table>
			<br>
			<br>
			<br>
		</div>
	</div>
	
	
	<script type="text/javascript">  
		function deleteCoursePlan(id) {
	        $.ajax({
	            url: 'mc/deleteCoursePlan',
	            type: 'POST',
	            data: {cpid: id}, 
	            success: function () {
	            	$("#tr" + id).remove(); 
	            },
	            error: function (req, status, error) {
	                alert("不可删除当前开课计划 ！" + error);
	            }
	        });
	    };	
		$(document).ready(function(){
			$("#getCoursePlan").click(function(){
		 		$.ajax({
		 			url: 'mc/getCoursePlan',
		 			type: 'GET',
		 			data: {mjid: $("#selectMj").val(), termId: $("#selectTerm").val()},
		 			success: function(data){
		 				if(data==""){
		 					alert("未查询到开课计划，请先添加开课计划！");
		 				}
		 				$("#cp").empty(coursepl);
		 				var coursepl = "";
		 				$.each(data,function(index,value){
		 					var str="";
		 					if(value.classrmtype==1) {str="普通教室"};
		 					if(value.classrmtype==2) {str="多媒体教室"};
		 					coursepl ="<tr id=\"tr"+value.cpid+"\">"+
							"<td>"+value.cpid+"</td>"+
							"<td>"+value.lessionPlan.term.tyear+value.lessionPlan.major.mjname+"</td>"+
							"<td>"+value.batch.bname+"</td>"+
							"<td>"+value.teacher.tname+"</td>"+
							"<td>"+value.lessionPlan.course.cname+"</td>"+
							"<td>"+str+"</td>"+
							"<td>"+"<a href=\"mc/toAddStructure?cpid="+value.cpid+"&bid="+value.batch.bid+"\">排课</a>"+
							"<a href=\"javascript:deleteCoursePlan("+value.cpid+");\">删除</a>"+"</td>"+
							"</tr>";
							$("#cp").append(coursepl);
						});
		 			},
		 			error: function(req,status,error){
		 				alert("请填写完整信息！");
		 			}
		 		});
		 		
		 	});
			$("#selectAcdm").change(function(){
		   		   var str2 = "<option>请选择专业</option>";
					$.ajax({
						url: 'mc/getMajorByacdmid',
						type: 'GET',
						data: {acdmid: $("#selectAcdm").val()},
						success: function(data){
							var str1 = "";
							$("#selectMj").empty();
						 	$("#selectMj").append(str2); 
							$.each(data,function(index,value){
								str1 = "<option value='"+ value.mjid +"'>" +  value.term.tyear + value.mjname + "</option>";
								$("#selectMj").append(str1);
							});
						},
						error: function(req,status,error){
							$("#selectMj").empty();
							$("#selectMj").append(str2);
						}
					});
				});
		});
    </script>
</body>
</html>